package com.zx.dao.impl;

import com.zx.bean.PerformanceResult;
import com.zx.dao.PerformanceResultDao;
import com.zx.util.DruidUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class PerformanceResultDaoImpl implements PerformanceResultDao {
    public final String SQL_INSERT="insert into performance_result " +
            "(PLOT_RATIO,POLLUTION_PRODUCTION_PER_UNIT_PRODUCT," +
            "EXHAUST_GAS_PRODUCTION_PER_UNIT_PRODUCT,AMOUNT_OF_WASTE_WATER_PRODUCED_PER_UNIT_PRODUCT," +
            "CONSUMPTION_OF_RAW_MATERIALS_PER_UNIT_OF_PRODUCT,COMPERHENSIVE_UTILIZATION_RATE_OF_INDUSTRIAL_SOLID_WASTE," +
            "WASTE_WATER_RECYCLING_RATE,COMPREHENSIVE_ENERGY_CONSUMPTION_PER_UNIT_PRODUCT," +
            "CARBON_EMISSION_PER_UNIT_PRODUC,YEAR,MOUNTH,COMPANYNO)" +
            "values(?,?,?,?,?,?,?,?,?,?,?,?)";
    @Override
    public boolean insert(PerformanceResult performanceResult) {
        Connection connection= DruidUtil.getConnection();
        PreparedStatement preparedStatement=null;
        try {
            preparedStatement=connection.prepareStatement(SQL_INSERT);
            preparedStatement.setDouble(1,performanceResult.getPlotRatio());
            preparedStatement.setDouble(2,performanceResult.getPollutionProductionPerUnitProduct());
            preparedStatement.setDouble(3,performanceResult.getExhaustGasProductionPerUnitProduct());
            preparedStatement.setDouble(4,performanceResult.getAmountOfWasteWaterProducedPerUnitProduct());
            preparedStatement.setDouble(5,performanceResult.getConsumptionOfRawMaterialsPerUnitOfProduct());
            preparedStatement.setDouble(6,performanceResult.getComperhensiveUtilizationRateOfIndustrialSolidWaste());
            preparedStatement.setDouble(7,performanceResult.getWasteWaterRecyclingRate());
            preparedStatement.setDouble(8,performanceResult.getComprehensiveEnergyConsumptionPerUnitProduct());
            preparedStatement.setDouble(9,performanceResult.getCarbonEmissionPerUnitProduc());
            preparedStatement.setString(10,performanceResult.getYear());
            preparedStatement.setString(11,performanceResult.getYear());
            preparedStatement.setString(12,performanceResult.getCompanyNo());
            return preparedStatement.executeUpdate()>0?true:false;
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            DruidUtil.close(connection,preparedStatement,null);
        }
        return false;
    }
}
